home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / misc / FetchRefs1.3.lha / FetchRefs1.3 / Scripts / GoFetchRefs.ced < prev    next >
Encoding:
Text File  |  1996-02-24  |  2.7 KB  |  106 lines

  1. /*  $VER: GoFetchRexx.ced 1.2 (24.2.96)
  2. **
  3. **   ARexx script to invoke FetchRefs from CygnusEd.
  4. **   Thanks to Lars MeldgĂ„rd for additional code.
  5. */
  6.  
  7. OPTIONS RESULTS
  8. OPTIONS FAILAT 20
  9. caller = ADDRESS()
  10.  
  11. /* Static part of the ARexx port name of the editor. That is, the name before 
  12.  * any suffixes (like '.1') are appended.
  13.  */
  14. editorname = 'rexx_ced'
  15.  
  16. /* Exit if we are not called from the editor */
  17. IF (LEFT(caller, LENGTH(editorname)) ~= editorname) then
  18.     EXIT 10
  19.  
  20. /* Get the current word from the editor. */
  21.  
  22. /* Get some data from the editor (line contents and cursor position) */
  23. Status 55
  24. line = result
  25. Status 46
  26. position = result + 1
  27.  
  28. /* Account for tabs (replace them with spaces) */
  29. Status 7
  30. tabtable = result
  31. tabchar = '09'X
  32. i = INDEX(line, tabchar)
  33. DO WHILE i > 0 & i <= position
  34.     leftstr = LEFT(line, i - 1)
  35.     line = LEFT(leftstr, INDEX(tabtable, 'T', i), ' ') || SUBSTR(line, i + 1)
  36.     i = INDEX(line, tabchar, i)
  37. END
  38.  
  39. /* Go left from the cursor */
  40. left = position
  41. char = SUBSTR(line, left, 1)
  42. DO WHILE (DATATYPE(char,'A') | char = '_') & (left > 0)
  43.    left = left - 1
  44.    IF left > 0 THEN 
  45.       char = SUBSTR(line, left, 1) 
  46. END
  47.  
  48. /* Now go right from the cursor */
  49. right = position
  50. char = SUBSTR(line, right, 1)
  51. DO WHILE (DATATYPE(char, 'A') | char = '_')
  52.    right = right + 1
  53.    char = SUBSTR(line, right, 1)
  54. END
  55.  
  56. IF right = left THEN
  57.    function = ''
  58. ELSE
  59.    function = SUBSTR(line, left + 1, right - (left + 1))
  60.  
  61. /* It doesn't matter whether we want a taglist, varargs og whatever function */
  62. IF RIGHT(function, 7) = "TagList" THEN
  63.     function = LEFT(function, LENGTH(function) - 7)
  64. ELSE IF RIGHT(function, 4) = "Tags" THEN
  65.     function = LEFT(function, LENGTH(function) - 4)
  66. ELSE IF RIGHT(function, 1) = "A" THEN
  67.     function = LEFT(function, LENGTH(function) - 1)
  68.  
  69. /* Define a temporary filename to put the reference into */
  70. filename = 'T:FR_' || function
  71.  
  72. /* Call FetchRefs to get the reference cut out to a temporary file */
  73. ADDRESS 'FETCHREFS'
  74. FR_GET function || '(%|Tags|TagList|A)' filename FILEREF
  75. gotoline = rc2
  76.  
  77. /* Address editor again to load the file or report error */
  78. ADDRESS VALUE caller
  79.  
  80. IF rc ~= 0 THEN DO
  81.     /* Skip if the error code is less than six. If the "Select reference"
  82.      * window is cancelled five is returned and as this is no error,
  83.      * we do not want to report it (uses time to 'Okay' the requester).
  84.      */
  85.     IF rc <= 5 THEN
  86.     EXIT 0
  87.  
  88.     /* Report the error (obtained from FetchRefs) through the editor. */
  89.     'okay1' RC2
  90.  
  91.     EXIT 0 
  92. END
  93. ELSE DO
  94.     /* Make the editor open a new window and load the autodoc into it. */
  95.     'Open New'
  96.     'Open' filename
  97.     'Editable file'
  98.     IF gotoline ~= 0 THEN
  99.     'jump to line' gotoline
  100.  
  101.     /* Delete the autodoc file */
  102.     ADDRESS COMMAND 'C:Delete >NIL:' filename
  103.  
  104.     EXIT 0
  105. END
  106.